package com.aaa.controller;

import com.aaa.entity.Type;
import com.aaa.service.impl.TypeServiceImpl;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("type")
@RestController
public class TypeController {
    @Resource
    TypeServiceImpl typeService;

    @RequestMapping("find")
   public List<Type> find(){
       return typeService.find();
   }

    @ResponseBody
    @RequestMapping("add")
    public Integer add(Type type){
        return  typeService.add(type);
    }

    @ResponseBody
    @RequestMapping("delete")
    public int delete(Integer tid){
        return typeService.delete(tid);
    }

    @ResponseBody
    @RequestMapping("update")
    public int update(Type type){
        return  typeService.update(type);
    }


    @ResponseBody
    @RequestMapping("findpage")
    public Map<String, Object> find(Integer pageSize, Integer pageNum){
        Map<String, Object> map = new HashMap<>();
        List<Type> userList = typeService.findpage(pageSize, pageSize*pageNum );
        Integer TotalNum = typeService.findcount();
        map.put("userList", userList);
        map.put("TotalNum", TotalNum);
        return map;
    }
}
